package com.yoda.youdianda.vo;

import com.yoda.youdianda.domain.SysRole;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Objects;

/**
 * @author shawn
 * @date 2022年 11月 14日 14:48
 * 角色权限管理vo
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
public class RolePageVo {
    private String id;
    private String name;
    private String description;
    private String create_date;
    private String update_date;
    private String del_flag;
    private Integer superadmin;
    private String default_data;
    private String role_id;
    private String role_menus;//菜单id集合字符串 eg: "1,2,3"

    public static RolePageVo init(SysRole role, List<String> list, SimpleDateFormat format) {
        RolePageVo vo = new RolePageVo();
        BeanUtils.copyProperties(role, vo);
        vo.setDel_flag(role.getDelFlag());
        vo.setDefault_data(role.getDefaultData());
        vo.setCreate_date(format.format(role.getCreateDate()));
        if (!Objects.isNull(role.getUpdateDate())) {
            vo.setUpdate_date(format.format(role.getUpdateDate()));
        }
        vo.setRole_id(role.getId());
        String role_menus = list.toString();
        vo.setRole_menus(role_menus.substring(1, role_menus.length() - 1));
        return vo;
    }
}